import QtQuick 2.6
import QtQuick.Layouts 1.2

import "../../../../Base/UiBase"
import Code 1.0
import "../../../../Base/Config"
import TCItem 1.0

Rectangle {
    id: root
    property int commentId
    property string username
    property int subject
    property date time
    property string comment
    property int upNumber
    property bool up: false


    width: parent.width
    height: body.y + body.height
    color: !(index % 2) ? Color.foregroundDarker : Color.foreground

    Column {
        id: body
        width: parent.width
        anchors {
            top: parent.top
            topMargin: Size.comment.topMargin
            left: parent.left
            leftMargin: Size.comment.leftMargin
            right: parent.right
            rightMargin: Size.comment.rightMargin
        }

        // top block : username
        Row {
            height: 60 * Size.ratio

            //username
            Text {
                id: username
                anchors.verticalCenter: parent.verticalCenter
                text: root.username
                font.pixelSize: Size.normalFont
            }

            // subject
            SubjectImage {
                anchors.verticalCenter: parent.verticalCenter
                subject: root.subject
            }
        }

        // comment
        Text {
            width: parent.width
            height: 30 * Size.ratio
            text: root.comment
            font.pixelSize: Size.normalFont
        }

        // bottom block : time, new comment
        RowLayout {
            width: parent.width
            height: 50 * Size.ratio

            spacing: 0

            // time
            Text {
                id: timetext
                anchors.verticalCenter: parent.verticalCenter
                text: Helper.dateToReadable(root.time)
                font.pixelSize: Size.smallFont
            }

            // spacer
            Item {
                Layout.fillHeight: true
                Layout.fillWidth: true
            }

            // up
            ImageButton {
                id: upButton
                property bool activated: root.up

                onClicked: root.up = !root.up
                anchors.verticalCenter: parent.verticalCenter
                Layout.alignment: Qt.AlignRight
                Layout.preferredWidth: 118 * Size.ratio
                Layout.preferredHeight: 50 * Size.ratio

                source: activated ? "../../../../../resources/tcommunity/posts/zan02.svg" : "../../../../../resources/tcommunity/posts/zan01.svg"

                Text {
                    id: upNumberLabel

                    anchors {
                        verticalCenter: parent.verticalCenter
                        left: parent.right
                        leftMargin: -47 * Size.ratio
                    }

                    font.pixelSize: Size.smallFont

                    text: String(root.upNumber + upButton.activated)
                }
            }
        }
    }
    BottomDivider{}
}
